import flask
from flask import Flask
import time
import json
app = Flask("FlaskProj")

# host = request.host_url

@app.route("/")
def index():

    url = flask.url_for("static", filename="hello.css")
    print("url:" + url)
    return "index"

@app.route("/test")
def test():
    # url = "http://localhost:5000" + flask.url_for("static", filename="hello.css")
    # r = requests.get(url)
    # print(r.text)

    # testupload()

    # return testreadjson()

    return ""
    pass

@app.route("/upload", methods=["post"])
def upload():
    fname = flask.request.files["file1"]
    if fname:
        t = time.strftime("%Y-%m-%d %H:%M:%S")
        new_name = r"uploads/" + t + fname.filename
        fname.save(new_name)
    pass

def testupload():
    # path = mostone.MOKA().IAP_PATH + "/display.png"
    # files = {"file1": open(path, "rb")}
    # url = "http://localhost:5000" + "/upload"
    # response = requests.post(url, files=files)
    # print(response)

    pass

def testreadjson():
    filepath = "./jsonfiles/product.json"
    with open(filepath, "r") as file:
        data = json.load(file)
        print(data)
        result = json.dumps(data)
        print(result)
        return result

